varying vec4 pColor;			//	fragment color, already interpolated for this fragment

//	the following variables are all in eye space
varying vec3 pNormal;			//	normal vector, already interpolated for this fragment
varying vec3 pEyeVec;			//	the point to eye, already interpolated for this fragment
varying vec3 lightDir;			//	the point to light, already interpolated for this fragment


uniform vec3 ambientIntensity; 
uniform vec3 diffuseIntensity; 
uniform vec3 specularIntensity;	//	intensity of 3 light ingredient

uniform vec3 diffuseMaterial; 
uniform vec3 specularMaterial;	//	material's reflection coefficient for light
uniform float shiness;			//	specular shiness

void main() 
{
	vec3 final_color = ambientIntensity;
	
	vec3 N = normalize(pNormal);
	vec3 L = normalize(lightDir);
	float dotTerm = dot(N, L);
	if (dotTerm > 0.0)
    {
		final_color += diffuseIntensity * diffuseMaterial * dotTerm;
		vec3 E = normalize(pEyeVec);
		vec3 R = reflect(-L, N);		//	reflect light
		float dotTerm2 = dot(R, E);
		if (dotTerm2 > 0.0)
			final_color += specularIntensity * specularMaterial * pow(dotTerm2, shiness);	
    }

	//	Todo: include the original material color
	gl_FragColor = vec4(final_color, 1.0);
} 